#include "Tren.h"

GLfloat dA = 1, dB = 1, dC = 1;
GLfloat vel = 1.9;

Tren::Tren(){
    
}

void Tren::CilindroGrande() {
    glPushMatrix();
    glColor4ub(0, 255, 0, 0);
    GLUquadricObj* eje = gluNewQuadric();
    gluQuadricDrawStyle(eje, GLU_FILL);
    gluCylinder(eje, 15, 15, 30, 30, 10);
    gluDeleteQuadric(eje);
    glPopMatrix();
}

void Tren::Cilindro(int val) {
    GLUquadricObj * eje = gluNewQuadric();
    glColor4ub(184, 134, 011, 0);
    if (val == 0) {
        glPushMatrix();
        glTranslated(9.5, 11.5, 0);
        gluCylinder(eje, 0.5, 0.5, 30, 40, 10);
        glPopMatrix();
    } else if (val == 1) {
        glPushMatrix();
        glTranslated(-9.5, 11.5, 0);
        gluCylinder(eje, 0.5, 0.5, 30, 40, 10);
        glPopMatrix();
    }else{
        glPushMatrix();
        glTranslated(-39.5, 11.5, 0);
        gluCylinder(eje, 0.5, 0.5, 30, 40, 10);
        glPopMatrix();
    }
}

void Tren::secCilGrand(int val) {
    glPushMatrix();
    GLUquadricObj* eje = gluNewQuadric();
    gluQuadricDrawStyle(eje, GLU_FILL);
    gluQuadricNormals(eje, GLU_SMOOTH);
    if (val == 1) {
        glTranslatef(0, 0, -50);
        glColor4ub(255, 0, 0, 0);
        gluCylinder(eje, 15.5, 15.5, 1, 30, 30);
        Cilindro(0);
        Cilindro(1);
        CilindroGrande();
    } else if (val == 2) {
        glTranslatef(0, 0, -25);
        glColor4ub(255, 0, 0, 0);
        gluCylinder(eje, 15.5, 15.5, 1, 30, 30);
        Cilindro(0);
        Cilindro(1);
        CilindroGrande();
        glColor4ub(255, 0, 0, 0);
        glTranslatef(0, 0, 30);
        gluCylinder(eje, 15.5, 15.5, 1, 30, 30);

    } else if (val == 3) {
        glTranslatef(0, 0, 5);
        glColor4ub(0, 0, 200, 0);
        gluCylinder(eje, 15, 15, 15, 30, 10);
        glTranslatef(0, 0, 15.5);
        glScalef(1, 1, 0.7);
        glutSolidSphere(15, 30, 30);
        glTranslatef(0, 0, 15);
        gluCylinder(eje, 5, 5, 2, 30, 30);
        glTranslatef(0, 0, 2);
        gluCylinder(eje, 5, 0, 0.1, 30, 1);
    }else{
        glTranslatef(0, 0, -65);
        gluCylinder(eje,15, 15, 15, 30, 10);
        glTranslatef(0, 0, -0.5);
        gluCylinder(eje, 12.5, 15, 1, 30, 30);
        glTranslatef(0, 0, -0.1);
        gluCylinder(eje, 0.0001, 12.5, 0.1, 30, 30);
        glTranslatef(0, 0, -1.5);
        gluCylinder(eje, 7.5, 7.5, 3.5, 30, 30);
        glTranslatef(0, 0, -1.5);
        gluCylinder(eje, 0.0001, 7.5, 0.1, 30, 30);
        glTranslatef(0, 0, -1.5);
        gluCylinder(eje, 5.5, 5.5, 1.5, 30, 30);
        glTranslatef(0, 0, -1.5);
        gluCylinder(eje, 0.0001, 5.5, 0.5, 30, 30);
        
        glPushMatrix();
        glTranslatef(-8, 4, 6);
        glRotated(90, 1, 0, 0);
        gluCylinder(eje, 1, 1, 10, 30, 30);
        glPopMatrix();
        
        glPushMatrix();
        glTranslatef(10, 4, 0.5);
        glRotated(90, 1, 0, 0);
        gluCylinder(eje, 1, 1, 12, 30, 30);
        glPopMatrix();
        
        
        glPushMatrix();
        glTranslatef(10.5, 0, 0);
        glRotatef(-45, 0, 1, 0);
        gluCylinder(eje, 1, 1, 10.5, 30, 30);
        glTranslatef(0, -5, 0);
        gluCylinder(eje, 1, 1, 10.5, 30, 30);
        glPopMatrix();
        
        glPushMatrix();
        glTranslatef(0, 15, 5);
        gluCylinder(eje, 5, 5, 3.5, 30, 30);
        glPushMatrix();
        
        gluCylinder(eje, 5, 0.1, 0.1, 30, 30);
        
        glTranslatef(0, 0, 1.5);
        gluCylinder(eje, 5, 0.1, 0.1, 30, 30);
        glPopMatrix();
        glPopMatrix();
        
    }
    glPopMatrix();
    gluDeleteQuadric(eje);
}

void Tren::gasoducto() {
    glPushMatrix();
    GLUquadricObj* eje = gluNewQuadric();
    glTranslatef(0, 45, 15);
    glRotatef(90, 1, 0, 0);
    gluCylinder(eje, 3.5, 3.5, 30, 30, 30);
    glTranslatef(0, 0, -5);

    gluCylinder(eje, 7.5, 3.5, 9, 30, 30);
    glTranslatef(0, 0, -5);

    gluCylinder(eje, 3.5, 7.5, 5, 30, 30);
    glTranslatef(0, 0, -3);
    gluCylinder(eje, 3.5, 3.5, 3, 30, 30);
    gluDeleteQuadric(eje);
    glPopMatrix();
}

void Tren::Batiforma() {
    glPushMatrix();
    glTranslatef(0, 13, 27);
    glColor4ub(255, 0, 0, 0);
    glBegin(GL_POLYGON);
    glVertex3f(5, 0, 0);
    glVertex3f(-5, 0, 0);

    glVertex3f(-5, -0.5, 0);
    glVertex3f(-5, -1.5, 0);

    glVertex3f(-5, -1.5, 0); //
    glVertex3f(-9.5, -1.5, 0);

    glVertex3f(-9.5, -1.5, 0); //
    glVertex3f(-9.5, -1.5, 1.5);

    glVertex3f(-9.5, -1.5, 1.5); //
    glVertex3f(-11.9, -1.5, 1.9);

    glVertex3f(-11.9, -1.5, 1.9); //
    glVertex3f(-13.5, -1.5, 0);

    glVertex3f(-13.5, -1.5, 0); //
    glVertex3f(-15.5, -1.5, 0);

    glVertex3f(-15.5, -1.5, 0); //
    glVertex3f(-15.5, -1.9, 1);

    glVertex3f(-15.5, -1.9, 1); //
    glVertex3f(-15.5, -1.5, 3);

    glVertex3f(-15.5, -1.5, 3);
    glVertex3f(-15.5, -2.5, 5);

    glVertex3f(-15.5, -2.5, 5);
    glVertex3f(-15.5, -1.5, 5);

    glVertex3f(-15.5, -1.5, 5);
    glVertex3f(-5.5, -1.5, 11.5);

    glVertex3f(-5.5, -1.5, 11.5);
    glVertex3f(-5.5, -0.5, 11.5);

    glVertex3f(-5.5, -0.5, 11.5);
    glVertex3f(5.5, -0.5, 11.5);

    glVertex3f(5.5, -0.5, 11.5);
    glVertex3f(5.5, -1.5, 11.5);

    glVertex3f(5.5, -1.5, 11.5);
    glVertex3f(15.5, -1.5, 5);

    glVertex3f(15.5, -1.5, 5);
    glVertex3f(15.5, -2.5, 5);

    glVertex3f(15.5, -2.5, 5);
    glVertex3f(15.5, -1.5, 3);

    glVertex3f(15.5, -1.5, 3);
    glVertex3f(15.5, -1.9, 1);

    glVertex3f(15.5, -1.9, 1);
    glVertex3f(15.5, -1.5, 0);

    glVertex3f(15.5, -1.5, 0);
    glVertex3f(13.5, -1.5, 0);

    glVertex3f(13.5, -1.5, 0);
    glVertex3f(11.9, -1.5, 1.9);

    glVertex3f(11.9, -1.5, 1.9);
    glVertex3f(9.5, -1.5, 1.5);

    glVertex3f(9.5, -1.5, 1.5);
    glVertex3f(9.5, -1.5, 0);

    glVertex3f(9.5, -1.5, 0);
    glVertex3f(5, -1.5, 0);

    glVertex3f(5, -1.5, 0);
    glVertex3f(5, -0.5, 0);
    glEnd();
    glPopMatrix();
}

void Tren::faro() {
    GLUquadricObj* eje = gluNewQuadric();
    gluQuadricDrawStyle(eje, GL_FILL);
    glPushMatrix();
    glTranslatef(0, 19.5, 35);
    glPushMatrix();
    glScalef(0.7, 1, 0.5);
    glutSolidCube(13);
    glTranslatef(0, 13, 0);
    glRotatef(90, 1, 0, 0);
    glRotatef(45, 0, 0, 1);
    gluCylinder(eje, 4, 9.5, 7, 4, 30);
    gluCylinder(eje, 0, 4, 1, 4, 30);
    glRotatef(45, 0, 0, 1);
    glRotatef(90, 1, 0, 0);
    glutSolidCube(5);
    glPopMatrix();

    gluCylinder(eje, 4.5, 4.5, 5, 30, 30);
    glColor4ub(150, 150, 150, 0);
    glTranslatef(0, 0, 4);
    gluCylinder(eje, 4.5, 0, 0.1, 30, 30);
    glPopMatrix();
}

void Tren::fig1() {
    glPushMatrix();
    glTranslatef(0, 12, -10);
    glScalef(0.5, 0.5, 0.5);
    GLUquadricObj* eje = gluNewQuadric();
    gluQuadricDrawStyle(eje, GL_FILL);
    glRotatef(-90, 1, 0, 0);
    gluCylinder(eje, 10, 10, 15, 30, 30);
    glTranslatef(0, 0, 15);
    gluCylinder(eje, 10, 8, 3, 30, 30);
    glTranslatef(0, 0, 3);
    gluCylinder(eje, 8, 8, 10, 30, 30);
    glTranslatef(0, 0, 10);
    gluCylinder(eje, 8, 10, 5, 30, 30);
    glTranslatef(0, 0, 3);
    gluCylinder(eje, 10, 10, 1.5, 30, 30);
    glTranslatef(0, 0, 1);
    gluCylinder(eje, 10, 0.5, 5.5, 30, 30);
    glTranslatef(0, 0, 3.5);
    gluCylinder(eje, 1.5, 1.5, 3.5, 8, 30);
    glTranslatef(0, 0, 3.5);
    gluCylinder(eje, 1.5, 0, 0.1, 8, 30);
    glPopMatrix();
}

void Tren::fig2() {
    glPushMatrix();
    glTranslatef(0, 13.5, -37);
    glScalef(0.7, 0.7, 0.7);
    glRotatef(180, 0, 1, 0);


    GLUquadricObj* eje = gluNewQuadric();
    gluQuadricDrawStyle(eje, GL_FILL);
    glRotatef(-90, 1, 0, 0);
    gluCylinder(eje, 10, 10, 15, 30, 30);
    glTranslatef(0, 0, 15);
    gluCylinder(eje, 10, 8, 3, 30, 30);
    glTranslatef(0, 0, 3);
    gluCylinder(eje, 8, 8, 10, 30, 30);
    glTranslatef(0, 0, 10);
    gluCylinder(eje, 8, 10, 5, 30, 30);
    glTranslatef(0, 0, 3);
    gluCylinder(eje, 10, 10, 1.5, 30, 30);

    glPushMatrix();
    glTranslatef(-5, -5, -5);
    glRotatef(90, 1, 0, 0);
    gluCylinder(eje, 1.5, 1.5, 7, 4, 30);
    glTranslatef(0, 0, 6);
    gluCylinder(eje, 1.5, 0, 0.1, 4, 30);
    glRotatef(-90, 1, 0, 0);
    gluCylinder(eje, 1.5, 1.5, 7, 30, 30);
    glTranslatef(0, 0, 7);
    gluCylinder(eje, 1.5, 0.7, 3, 30, 30);
    glTranslatef(0, 0, 1.5);
    gluCylinder(eje, 0.7, 1.5, 1.5, 30, 30);
    glTranslatef(0, 0, 0.5);
    gluCylinder(eje, 1.5, 1.5, 5, 30, 30);
    glTranslatef(0, 0, 5);
    gluCylinder(eje, 1.5, 0.5, 0.1, 30, 30);
    glTranslatef(0, 0, 0.1);
    gluCylinder(eje, 0.9, 1.5, 3, 30, 30);
    glTranslatef(0, 0, 2.5);
    gluCylinder(eje, 1.5, 2.5, 3, 4, 30);
    glTranslatef(0, 0, 3.5);
    glPushMatrix();
    glScalef(1, 0.9, 0.5);
    glutSolidCube(5);
    glPopMatrix();
    glTranslatef(0, 0, 0.5);
    gluCylinder(eje, 1.5, 1.5, 1.5, 30, 30);
    glTranslatef(0, 0, 1.5);
    gluCylinder(eje, 1.5, 2.5, 1, 30, 30);
    glTranslatef(0, 0, 1);
    gluCylinder(eje, 2.5, 2.5, 3, 30, 30);
    glTranslatef(0, 0, 2);
    gluCylinder(eje, 2.5, 2, 3, 30, 30);
    glTranslatef(0, 0, 2);
    gluCylinder(eje, 2, 1.5, 1.5, 30, 30);
    glTranslatef(0, 0, 1.5);
    gluCylinder(eje, 1.5, 0, 0.1, 30, 30);
    glPopMatrix();


    glTranslatef(0, 0, 1);
    gluCylinder(eje, 10, 3.5, 5.5, 30, 30);

    gluCylinder(eje, 3.5, 3.5, 10, 30, 30);
    glTranslatef(0, 0, 10);
    gluCylinder(eje, 3.5, 4.5, 1.5, 30, 30);
    glTranslatef(0, 0, 0.5);
    gluCylinder(eje, 4.5, 4.5, 3.5, 30, 30);
    glTranslatef(0, 0, 3.5);
    gluCylinder(eje, 4.5, 0, 0.1, 30, 30);

    glPushMatrix();
    glRotatef(90, 0, 0, 1);
    glScalef(1, 0.7, 1);
    glutSolidCube(5);
    glTranslatef(0, 0, 3);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(0, 1.5, 2.5);
    gluCylinder(eje, 0.5, 0.5, 1.5, 30, 30);
    glTranslatef(0, 0, 1.5);
    gluCylinder(eje, 0.5, 1, 0.4, 30, 30);
    glTranslatef(0, 0, 0.5);
    gluCylinder(eje, 1, 1, 1, 30, 30);
    glTranslatef(0, 0, 0.5);
    gluCylinder(eje, 1, 0.5, 1, 30, 30);
    glTranslatef(0, 0, 0.5);
    gluCylinder(eje, 0.5, 0, 0.1, 30, 30);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(0, -1.5, 2.5);
    gluCylinder(eje, 0.5, 0.5, 1.5, 30, 30);
    glTranslatef(0, 0, 1.5);
    gluCylinder(eje, 0.5, 1, 0.4, 30, 30);
    glTranslatef(0, 0, 0.5);
    gluCylinder(eje, 1, 1, 1, 30, 30);
    glTranslatef(0, 0, 0.5);
    gluCylinder(eje, 1, 0.5, 1, 30, 30);
    glTranslatef(0, 0, 0.5);
    gluCylinder(eje, 0.5, 0, 0.1, 30, 30);
    glPopMatrix();

    glPopMatrix();
}

void Tren::Campana() {
    GLUquadricObj* eje = gluNewQuadric();
    glPushMatrix();
    gluQuadricDrawStyle(eje, GL_FILL);
    glTranslatef(0, 20.5, -23);
    glScalef(0.4, 0.4, 0.4);
    glRotatef(90, 1, 0, 0);
    gluCylinder(eje, 10, 10, 3.5, 30, 30);
    glTranslatef(0, 0, -3.3);
    GLfloat k = 7;
    gluCylinder(eje, k, 10, 3.5, 7, 30);
    glPushMatrix();
    glTranslatef(0, 0, 2.5);
    glutSolidSphere(5, 30, 30);
    glPopMatrix();
    for (int i = 0; i < 10; i++) {
        glTranslatef(0, 0, -1.3);
        gluCylinder(eje, k - 0.3, k, 1.5, 7, 30);
        k -= 0.25;
    }
    glTranslatef(0, 0, -1.3);
    gluCylinder(eje, 2.5, k, 1.5, 10, 30);
    glTranslatef(0, 0, -1);
    gluCylinder(eje, 0, 2.5, 1, 10, 30);
    glPushMatrix();
    glTranslatef(-2, 0, -7);
    glScalef(1, 0.5, 0.5);
    gluCylinder(eje, 3.5, 3.5, 20, 2, 30);
    glTranslatef(0, 0, 0);
    glScalef(0.2, 1, 1);
    glutSolidSphere(4, 10, 10);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(2, 0, -7);
    glScalef(1, 0.5, 0.5);
    gluCylinder(eje, 5, 5, 20, 2, 30);
    glTranslatef(0, 0, 0);
    glScalef(0.2, 1, 1);
    glutSolidSphere(4, 10, 10);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(-15.5, 0, -7);
    glRotatef(90, 1, 0, 0);
    glRotatef(90, 0, 1, 0);
    gluCylinder(eje, 0.5, 0.5, 30, 30, 30);
    glutSolidCube(1.5);
    glTranslatef(0, 0, 30);
    glutSolidCube(1.5);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(12.5, 0, -9);
    generaPoste();
    glTranslatef(-13 * 2, 0, 0);
    generaPoste();
    glPopMatrix();

    glPopMatrix();
    gluDeleteQuadric(eje);
}

void Tren::generaPoste() {
    GLUquadricObj* eje = gluNewQuadric();
    glPushMatrix();
    glScalef(1, 0.4, 1);
    gluQuadricDrawStyle(eje, GL_FILL);
    gluCylinder(eje, 5, 7, 45, 2, 10);
    glPopMatrix();
    gluDeleteQuadric(eje);
}

void Tren::posteFrente() {
    GLUquadricObj* eje = gluNewQuadric();
    gluQuadricDrawStyle(eje, GL_FILL);
    glPushMatrix();
    glTranslatef(-18.5, 0, 20);
    glPushMatrix();
    glRotatef(90, 0, 1, 0);
    gluCylinder(eje, 1.5, 1.5, 3.5, 30, 30);
    glTranslatef(-0.1, 0, 0);
    glRotatef(-90, 0, 1, 0);
    glRotatef(45, 1, 0, 0);
    glutSolidSphere(1.5, 30, 30);
    gluCylinder(eje, 1.5, 1.5, 30.5, 30, 30);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(37, 0, 0);
    glRotatef(-90, 0, 1, 0);
    gluCylinder(eje, 1.5, 1.5, 3.5, 30, 30);
    glTranslatef(-0.1, 0, 0);
    glRotatef(90, 0, 1, 0);
    glRotatef(45, 1, 0, 0);
    glutSolidSphere(1.5, 30, 30);
    gluCylinder(eje, 1.5, 1.5, 30.5, 30, 30);
    glPopMatrix();
    glPopMatrix();
}

void Tren::dibujaTrapecio() {
    glPushMatrix();
    glColor4ub(255, 0, 0, 0);
    glTranslatef(0, -5, 15);
    glScalef(1.5, 0.3, 1);
    glutSolidCube(30);
    glTranslatef(0, 0, 10);
    glScalef(1.52, 1, 1);
    glRotatef(45, 1, 0,0);
    
    glutSolidCone(10, 45, 30, 30);
    glPopMatrix();
}

void Tren::Frente() {
    GLUquadricObj* eje = gluNewQuadric();
    gluQuadricDrawStyle(eje, GL_FILL);
    glPushMatrix();
    glTranslatef(0, -8, -10.5);
    glScalef(0.3, 0.85, 1.6);
    glutSolidCube(40);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(-17, -23, 5);
    glRotatef(90, 0, 1, 0);
    gluCylinder(eje, 2, 2, 35, 30, 30);
    glTranslatef(40, 0, 0);
    gluCylinder(eje, 2, 2, 35, 30, 30);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(0, -15, 10);
    glPushMatrix();
    glScalef(1, 0.5, 1);
    glutSolidCube(20);
    glPopMatrix();
    glTranslatef(0, 0, 10);
    dibujaTrapecio();
    glPushMatrix();
    glTranslatef(-18, 0, 30);
    glRotatef(-90, 1, 0, 0);
    GLfloat val=1.5;
    for(int i=0; i<6; i++){
        gluCylinder(eje, val, val-0.1, 3, 30, 30);
        val-=0.1;
        glTranslatef(0, 0,3);
    }
    gluCylinder(eje, val, 0.1, 5,30, 30);
    glTranslatef(0, 0, 3.5);
    glutSolidSphere(1.5,30, 30 );
    glPushMatrix();
    glTranslatef(0, 5.5, -6.5);
    glScalef(0.1, 1, 1);
    glutSolidCube(10);
    glPopMatrix();
    glPopMatrix();
    
    glPushMatrix();
    glTranslatef(18, 0, 30);
    glRotatef(-90, 1, 0, 0);
    val=1.5;
    for(int i=0; i<6; i++){
        gluCylinder(eje, val, val-0.1, 3, 30, 30);
        val-=0.1;
        glTranslatef(0, 0,3);
    }
    gluCylinder(eje, val, 0.1, 5,30, 30);
    glTranslatef(0, 0, 3.5);
    glutSolidSphere(1.5,30, 30 );
    glPushMatrix();
    glTranslatef(0, 5.5, -6.5);
    glScalef(0.1, 1, 1);
    glutSolidCube(10);
    glPopMatrix();
    glPopMatrix();
    
    glPopMatrix();
}

void Tren::Vagon() {
    glPushMatrix();
    glColor4ub(255, 0, 0, 0);
    glTranslatef(0, 0, -50);

    glPushMatrix();
    glScalef(1, 1, 0.01);
    glutSolidCube(40);
    glPopMatrix();

    // Separadores de la vista del conductor
    glPushMatrix();
    glTranslatef(0, 25, 0);
    glScalef(0.1, 0.5, 0.01);
    glutSolidCube(40);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(-18, 25, 0);
    glScalef(0.1, 0.5, 0.01);
    glutSolidCube(40);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(18, 25, 0);
    glScalef(0.1, 0.5, 0.01);
    glutSolidCube(40);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(0, 35, 0);
    glScalef(1.0, 0.01, 0.1);
    glutSolidCube(40);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(0, 38, -20);
    glPushMatrix();
    glScalef(1.5, 0.15, 1.6);
    glutSolidCube(30);
    glPopMatrix();
    
    glPushMatrix();
    glTranslatef(20, -20, 0);
    glScalef(0.01, 1.5, 0.1);
    glutSolidCube(30);
    glPopMatrix();
    
    glPopMatrix();
    glPushMatrix();
    glTranslatef(-20, 5, -22);
    glPushMatrix();
    glScalef(0.01, 1.345, 1.5);
    glutSolidCube(30);
    glPopMatrix();
    
    
    glPushMatrix();
    glTranslatef(0, 15, 0);
    glScalef(0.01, 1.3, 0.1);
    glutSolidCube(30);
    glPopMatrix();
    
    
    glPushMatrix();
    glTranslatef(0, 15, -20);
    glScalef(0.01, 1.3, 0.1);
    glutSolidCube(30);
    glPopMatrix();
    
    glPopMatrix();

    
    glPushMatrix();
    glTranslatef(20, 5, -22);
    glScalef(0.01, 1.345, 1.5);
    glutSolidCube(30);
    glPopMatrix();
    
    
    glPushMatrix();
    glTranslatef(20, 15, -40);
    glScalef(0.01, 1.3, 0.1);
    glutSolidCube(30);
    glPopMatrix();
    
    
    glPushMatrix();
    glTranslatef(0, -15, -25);
    glScalef(1.3, 0.01, 1.7 );
    glutSolidCube(30);
    glPopMatrix();
   
    
    glPopMatrix();
}

void Tren::Rueda(GLfloat x, GLfloat z) {
    glPushMatrix();
    glPushMatrix();
    glTranslatef(x, 0, z);
    if (x > 0) {
        glRotatef(180, 0, 1, 0);
    }
    glPushMatrix();
    glPushMatrix();
    glColor4ub(190, 190, 190, 0);
    glTranslatef(-15, -20, 0);
    glRotatef(90, 0, 1, 0);
    glutSolidTorus(1.5, 11.5, 5, 32);
    glPopMatrix();

    glPushMatrix();
    glColor4ub(255, 0, 0, 0);
    glTranslatef(-15, -20, 0);
    glRotatef(90, 0, 1, 0);
    glutSolidTorus(1.0, 10.5, 5, 32);
    glPopMatrix();

    glPushMatrix();
    glColor4ub(255, 0, 0, 0);
    GLUquadricObj* eje1 = gluNewQuadric();
    gluQuadricDrawStyle(eje1, GLU_FILL);
    glTranslatef(-16, -20, 0);
    glRotatef(90, 0, 1, 0);
    gluCylinder(eje1, 5, 5, 2, 8, 8);
    glTranslatef(0, 0, -0.1);
    gluCylinder(eje1, 5, 0, 0.1, 8, 8);
    glTranslatef(0, 0, 0.2);
    gluCylinder(eje1, 5, 0, 0.1, 8, 8);
    gluDeleteQuadric(eje1);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(-16, -20, 0);
    glScalef(0.5, 1, 1);
    glutSolidCube(5);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(-15, -20, 0);

    GLfloat angulo = 0;
    for (int i = 0; i < 11; i++) {
        glPushMatrix();
        glRotatef(angulo, 1, 0, 0);
        glScalef(0.3, 4.5, 0.4);
        glutSolidCube(5);
        glPopMatrix();
        angulo += 36;
    }
    
    glPopMatrix();
    glPopMatrix();
    glPopMatrix();
}

void Tren::Ruedas() {
    glPushMatrix();
    glTranslatef(0, 0, 5.5);
    glScalef(1.15,1.15,1.15);
    Rueda(0.0, 0.0);
    Rueda(0.0, -35.0);
    Rueda(0.1, 0.0);
    Rueda(0.1, -35.0);
    glScalef(0.45, 0.45, 0.45);
    glTranslatef(0, -40.5, 20);
    Rueda(-18.5, 35.0);
    GLUquadricObj* eje=gluNewQuadric();
    gluQuadricDrawStyle(eje, GLU_FILL);
    glColor4ub(155, 155, 155, 0);
    
    glPushMatrix();
    glTranslatef(-33, -20, 35);
    glRotatef(90, 0, 1, 0);
    gluCylinder(eje, 2.5, 2.5, 67, 30, 30);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(0, -10, 30);
    glScalef(1.5, 2.5, 2);
    glutSolidCube(10);
    glPopMatrix();
    Rueda(18.5, 35.0);
    glPopMatrix();
}

void Tren::rueda2(){
    glPushMatrix();
    GLUquadricObj* eje=gluNewQuadric();
    glRotatef(90, 0, 1, 0);
    glColor4ub(255, 0, 0, 0);
    gluCylinder(eje, 10, 0.1, 0.1, 30, 30);
    glPushMatrix();
    glTranslatef(1, 0, 0);
    glRotatef(180, 0, 1, 0);
    gluCylinder(eje, 10, 0.1, 0.1, 30, 30);
    glPopMatrix();
    glColor4ub(150, 100, 100, 255);
    glutSolidTorus(2.5, 11.5, 30, 30);
    glPopMatrix();
}

void Tren::Vagon2(){
    glPushMatrix();
    glTranslatef(0, 0, -150);
    glPushMatrix();
    glScalef(1, 0.5, 1.5);
    glutSolidCube(50);
    glTranslatef(0, -20, 0);
    glScalef(1, 0.2, 1.3);
    glutSolidCube(50);
    glTranslatef(0, -25, 0);
    glScalef(1, 0.15, 1.1);
    glutSolidCube(50);
    glPopMatrix();
    
    GLUquadricObj* eje=gluNewQuadric();
    
    glPushMatrix();
    glTranslatef(0, 5, 0);
    glScalef(0.70, 1.33, 1);
    glPushMatrix();
    glTranslatef(25, -23, 25);
    glScalef(0.75, 0.7, 0.7);
    rueda2();
    glTranslatef(0, 0, -70);
    rueda2();
    glRotatef(-90, 0, 1, 0);
    gluCylinder(eje, 3.5, 3.5, 70, 30, 30);
    glPopMatrix();
    
    glPushMatrix();
    glTranslatef(-25, -23, 25);
    glScalef(0.7, 0.7, 0.7);
    rueda2();
    glPushMatrix();
    glRotatef(90, 0, 1, 0);
    gluCylinder(eje, 3.5, 3.5, 70, 30, 30);
    glPopMatrix();
    glTranslatef(0, 0, -70);
    rueda2();
    glPopMatrix();
    glPopMatrix();
    
    glPopMatrix();
}

void Tren::generaTren() {
    secCilGrand(1);
    secCilGrand(2);
    secCilGrand(3);
    secCilGrand(4);
    gasoducto();
    Batiforma();
    faro();
    Campana();
    fig1();
    fig2();
    posteFrente();
    Frente();
    Vagon();
    Ruedas();
    Vagon2();
    glPushMatrix();
    glTranslatef(0, -50, 0);
    glScalef(1, 0.5, 30);
    glutSolidCube(50);
    glPopMatrix();
}